import java.util.ArrayList;
import java.util.List;

public class PackBag {
    List<PokeBall> list = new ArrayList<>();

    public void addBall(){
        list.add(new PokeBall());
    }

    public void dropPokeball(){
        list.remove(this.getEmptyPokeBall());
    }
    public String checkPokeBall() {

        String str = "";

        if(!(list.isEmpty())){
            for (int i = 0; i < list.size(); i++) {
                PokeBall f = list.get(i);
                str += f.toString();
            }
        }
        return str;
    }
    public PokeBall getEmptyPokeBall(){
        for (PokeBall p:list){
            if (p.getPokemon()==null)
                return p;
        }
        return null;
    }

    public Pokemon getPokemon(){
        for (int i = 0; i < list.size(); i++) {
            PokeBall p = list.get(i);
            if(p.getPokemon()!= null){
                return p.getPokemon();
            }
        }
        return null;
    }

    public boolean checkAlivePokemon(){
        for (PokeBall p:list) {
            if(p.getPokemon()!=null){
                if (p.getPokemon().isHealth())
                return true;
            }
        }
        return false;
    }

    public void restoreHealth(){
        for (PokeBall p:list) {
            if (p.getPokemon()!=null){
                if (!p.getPokemon().isHealth()) {
                    p.getPokemon().setHealth(true);
                    p.getPokemon().setHP(100);
                }
            }
        }
    }

    public Pokemon getPokemon(String name){
        for (int i = 0; i < list.size(); i++) {
            PokeBall p = list.get(i);
            if (p.getPokemon()!=null){
                if(p.getPokemon().getName().equals(name)){
                    return p.getPokemon();
                }
            }
        }
        return null;
    }
}
